package com.zjs.jsp.ediorder.web;


import com.zjs.jsp.domain.axd.AxdOrderRootData;
import com.zjs.jsp.domain.axd.out.Event_log_details;
import com.zjs.jsp.ediorder.domain.mongodb.jsp_Status;
import com.zjs.jsp.ediorder.service.BaseOrderQueryService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * 查询订单
 *
 * @author 李文
 * @create 2017-10-11 13:42
 **/
@RestController
public class QueryOrderApiController extends BaseOrderQueryService
{
    private static final Logger LOGGER_FACTORY = LoggerFactory.getLogger(QueryOrderApiController.class);


    @Value("${clientFlag}")
    private String clientFlag;


    @ApiOperation(value = "查询订单", notes = "查询订单，批量查询")
    @ApiImplicitParam(name = "root", value = "数据", required = true, dataType = "AxdOrderRootData", paramType = "body")
    @PostMapping("/order/query/list/{uuid}")
    public String orderInquiry(@PathVariable String uuid, @RequestBody AxdOrderRootData root, HttpServletRequest request) {
        LOGGER_FACTORY.info(uuid + " 接受的数据是 " + root + "  " + com.zjs.jsp.domain.config.WebHelpService.getParameterMap(request));

        String d = this.queryOrder(root, uuid);
        LOGGER_FACTORY.info(uuid + "  响应数据 ：" + d);

        return d;
    }

    @Override
    public void getDate(List<Object> data, List<jsp_Status> s) {
        if (s.size() > 0) {
            if (s.size() == 1) {
                data.add(s.get(0));
            } else {
                jsp_Status status = new jsp_Status();
                List<Event_log_details> e = new ArrayList<>();
                for (int i = 0; i < s.size(); i++) {
                    if (i == 0) {
                        status = s.get(i);
                    } else {
                        e.add(s.get(i).toEvent_log_details());
                    }
                }
                status.setEvent_log_details(e);
                data.add(status);
            }
        }
    }

}
